<template>
	<view class="myorder">
		<view class="tabs">
			<u-tabs 
			:list="list1"
			:current="current"
			lineWidth="30" 
			style="width: 100%;"
			@click="changeCurrent"
			></u-tabs>
		</view>

		<view class="orderList" v-for="item in orderList" :key="item._id">
			<view class="box1">
				<view class="pic">
					<image :src="item.snack_id[0].imageValue"></image>
				</view>
				<view class="des">
					<text>{{item.snack_id[0].name}}</text>
				</view>
				<view class="price">
					<view>${{item.total}}</view>
					<view>共{{item.number}}个</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const db = uniCloud.database();
	const dbCmd = db.command;
	const CloudUser = uniCloud.importObject("users")
	const cloudShoppingCarts = uniCloud.importObject("shoppingCarts");
	const CloudOrder = uniCloud.importObject("order")
	export default {
		data() {
			return {
				current:0,
				user_id: '',
				orderList:"",
				list1: [{
					name: '全部',
				}, {
					name: '待付款',
				}, {
					name: '待发货',
				}, {
					name: '待收货'
				}, {
					name: '待自提'
				}, ]
			};
		},
		onLoad(e) {
			this.current=e.current;
			this.user_id = uni.getStorageSync("uni-id-pages-userInfo")._id;
			this.getMyorderbyState(this.current)
		},
		onShow() {
			
		},
		computed:{
			
		},
		methods: {
			changeCurrent(index){
				this.current=index.index;
				this.getMyorderbyState(this.current);
			},
			async getMyorder() {
				let a=db.collection("order").where({
					user_id:this.user_id
				}).field("snack_id,user_id,shopping_id,state,number,total").getTemp();
				let b=db.collection("Snacks").getTemp();
				let res =await db.collection(a,b).get();
				console.log(res);
				this.orderList=res.result.data;
			},
			
			async getMyorderbyState(index) {
				console.log(index);
				if(index==0){
					this.getMyorder();
				}else{
				let a=db.collection("order").where({
					user_id:this.user_id,
					state:index-1
				}).field("snack_id,user_id,shopping_id,state,number,total").getTemp();
				let b=db.collection("Snacks").getTemp();
				let res =await db.collection(a,b).get();
				console.log(res);
				this.orderList=res.result.data;
			 }
			}
		}
	}
</script>

<style lang="scss">
	.myorder {
		box-sizing: border-box;
		width: 100%;
		padding:20rpx 20rpx;
		.tabs {}

		.orderList {
			box-sizing: border-box;
			width: 100%;
			height: 300rpx;
			padding-top: 20rpx;
            border-bottom: 1rpx solid gray;
			.box1 {
				width: 100%;
				height: 200rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				.pic {
					width: 200rpx;
					height: 200rpx;
					image{
						width: 200rpx;
						height: 200rpx;
					}
				}
				.des {
					
				}
				.price {
					
				}
			}
		}
	}
</style>